package com.food.configure;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 过滤器拦截器等的配置类
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    /**
     * 解决跨域问题配置
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowCredentials(true)
                .allowedHeaders("*")
                .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTION")
                .maxAge(3600);
    }

    /**
     * 登录拦截器配置
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns("/login/login")
                .excludePathPatterns("/fileUtils/uploadFile")
                .excludePathPatterns("/images/**")
                .addPathPatterns("/**");
    }
}
